<template>
  <div style="height: calc(100vh); background-color: #fff">
    <van-search
      v-model="value"
      placeholder="输入影城名称"
      show-action
      @cancel="onCancel"
    />
    <div v-show="!value">
      <div class="close">
        <p>离你最近</p>
      </div>
      <div class="cinema-box">
        <div class="cinema-box-top">
          <div class="cinema-box-left">保利国际影城北京天安门店</div>
          <div class="cinema-box-right">北京大观楼影城</div>
        </div>
        <div class="cinema-box-mind">
          <div class="cinema-box-left">北京首都电影院西单店</div>
          <div class="cinema-box-right">北京地质礼堂影院</div>
        </div>
        <div class="cinema-box-bottom">
          <p>北京首都电影院中华店</p>
        </div>
      </div>
    </div>
    <ul v-for="item in list" :key="item.name" v-show="value" class="search-ul">
      <li class="name">{{ item.name }}</li>
      <li class="address">{{ item.address }}</li>
      <li class="price">¥ {{ item.latitude.toFixed(1) }} 起</li>
    </ul>
  </div>
</template>

<script>
import { getCinemaAPI } from "@/network/api";
export default {

  data() {
    return {
      value: "",
      moviesList: [],
      cityId: localStorage.getItem("cityId"),
    };
  },
  mounted() {
    this.cityId = localStorage.getItem("cityId") || 110100;
    getCinemaAPI({
      cityId: this.cityId,
      ticketFlag: 1,
      k: 2783633,
    }).then((res) => {
      console.log(res);
      this.moviesList = res.data.data.cinemas;
    });
  },
  methods: {
    onCancel() {
      this.$router.replace("/cinema");
    },
  },
  //通过计算属性过滤数据
  computed: {
    list: function () {
      var _this = this;
      //逻辑-->根据input的value值筛选moviesList中的数据
      var arrByZM = []; //声明一个空数组来存放数据
      for (var i = 0; i < this.moviesList.length; i++) {
        //for循环数据中的每一项（根据name值）
        if (this.moviesList[i].name.search(this.value) != -1) {
          //判断输入框中的值是否可以匹配到数据，如果匹配成功
          arrByZM.push(this.moviesList[i]);
          //向空数组中添加数据
        }
      }
      //逻辑-->升序降序排列  false: 默认从小到大  true：默认从大到小
      //判断，如果要letter不为空，说明要进行排序
      if (this.letter != "") {
        arrByZM.sort(function (a, b) {
          if (_this.original) {
            return b[_this.letter] - a[_this.letter];
          } else {
            return a[_this.letter] - b[_this.letter];
          }
        });
      }
      //返回筛选后的数据
      return arrByZM;
    },
  },
};
</script>

<style lang="less" scoped>
.close {
  padding-top: 15px;
  margin-left: 10px;
  border-top: 1px solid #f4f4f4;
  margin-bottom: 18px;
  p {
    font-size: 13px;
    color: #bdc0c5;
    line-height: 13px;
  }
}

.cinema-box {
  width: 100%;
  height: 130px;
  border-bottom: 1px solid #ededed;

  .cinema-box-top {
    width: 100%;
    height: 40px;
    display: flex;
    align-items: center;

    .cinema-box-left {
      font-size: 13px;
      height: 30px;
      width: 160px;
      background-color: hsla(0, 0%, 95.7%, 0.6);
      font-size: 13px;
      border-radius: 3px;
      text-align: center;
      line-height: 30px;
      margin-left: 15px;
    }

    .cinema-box-right {
      font-size: 13px;
      height: 30px;
      width: 120px;
      background-color: hsla(0, 0%, 95.7%, 0.6);
      font-size: 13px;
      border-radius: 3px;
      text-align: center;
      line-height: 30px;
      margin-left: 10px;
    }
  }
  .cinema-box-mind {
    width: 100%;
    height: 40px;
    display: flex;
    align-items: center;
    .cinema-box-left {
      font-size: 13px;
      height: 30px;
      width: 160px;
      background-color: hsla(0, 0%, 95.7%, 0.6);
      font-size: 13px;
      border-radius: 3px;
      text-align: center;
      line-height: 30px;
      margin-left: 15px;
    }

    .cinema-box-right {
      font-size: 13px;
      height: 30px;
      width: 120px;
      background-color: hsla(0, 0%, 95.7%, 0.6);
      font-size: 13px;
      border-radius: 3px;
      text-align: center;
      line-height: 30px;
      margin-left: 10px;
    }
  }

  .cinema-box-bottom {
    width: 100%;
    height: 40px;
    line-height: 40px;
    p {
      height: 30px;
      width: 150px;
      background-color: hsla(0, 0%, 95.7%, 0.6);
      font-size: 13px;
      border-radius: 3px;
      text-align: center;
      margin-left: 15px;
    }
  }
}
.search-ul {
  height: 45px;
  position: relative;
  background-color: #fff;
  padding: 15px;
  padding-left: 0;
  border-top: 1px solid #f4f4f4;
  padding-left: 20px;
  font-size: 15px;
  .name {
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .address {
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
    color: #797d82;
    font-size: 13px;
    margin-top: 5px;
  }
  .price {
    font-size: 11px;
    color: #ff5f16;
    text-align: right;
    position: relative;
    top: -45px;
  }
}
</style>
